home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 47.7z / BS1 part 47 / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].7z / ImageMaster RT v1.50b (1994)(Black Belt Systems)(Disk 6 of 7)[HD].adf / piarc.lzh.parta / dkbr.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-17  |  8KB  |  285 lines

  1. /*
  2.  * dkbr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: January 17th, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01
  9.  */
  10. parse arg '"' fullname '"'
  11. call pragma('stack',20000);
  12.  
  13. /*
  14.  * open rexxsupport.library -- needed for some functions
  15.  */
  16. if ~show('L',"rexxsupport.library") then do
  17.   if addlib('rexxsupport.library',0,-30,0) then do
  18.       /* everything's ok */
  19.     end;
  20.   else do
  21.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  22.     say 'Cannot operate targar.rexx without this library - sorry!';
  23.     exit 10;
  24.     end;
  25.   end;
  26.  
  27. /*
  28.  * This will automatically direct the script to the proper
  29.  * software, if it is running.
  30.  */
  31. prtnme = 'IP_Port'; /* assume Image Professional */
  32. if show('P','IP_Port') = 0 then do
  33.   if show('P','IM_Port') = 0 then do
  34.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  35.     say "This script requires IP, IM or IM F/c to run!";
  36.     exit(20);
  37.     end;
  38.   else do
  39.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  40.     end;                 /* We make em, user's break em.          */
  41.   end;
  42.  
  43. options;
  44. address;
  45.  
  46.   /*
  47.    * This code attempts to read a file called "picmdpath" from REXX:
  48.    * If it can't find it, the script will assume that the commands
  49.    * associated with this PI Module are in "c:". If the file exists,
  50.    * the script will look in the path that is specified in the file.
  51.    * If you create this file, you MUST put a complete, correct path
  52.    * in it; if the commands are in a sub-directory, you have to put
  53.    * the trailing slash on the path (like, device:dir/).
  54.    * 
  55.    */
  56.   cmdpath = 'c:';
  57.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  58.     do
  59.       cmdpath = readln(fhandle);
  60.       call close(fhandle);  /* close the file    */
  61.     end
  62.  
  63. if fullname = "" then do
  64.   prevpath = 'ram:'; /* put user in ram to start with... */
  65.  
  66.   if show('C',dkbpath) = 1 then do
  67.     prevpath = getclip(dkbpath);
  68.     end;
  69.  
  70.   address(prtnme);
  71.   options results;
  72.   'current';
  73.   bufdata = result; /* get name of buffer, if there is one */
  74.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  75.   if bname ~= '<none>' then do
  76.     bufname = bname;
  77.     end;
  78.   if (length(bufname) > 4) then do
  79.     epos = pos('.dis',bufname,length(bufname)-4);
  80.     if epos ~= 0 then do
  81.       bufname = left(bufname,epos-1)
  82.       end
  83.     end;
  84.   'filerequest "'||prevpath||'","'||bufname||'",".dis","Load DKB"';
  85.   DKBfile = result;
  86.   options;
  87.  
  88.   if DKBfile = 'FR_CANCELLED' then do
  89.     address(prtnme);
  90.     'imtofront';
  91.     exit 0;
  92.     end;
  93.  
  94.   DKBfile = expandfilename(DKBfile);
  95.   thispath = gimmepath(DKBfile);
  96.   call setclip(dkbpath,thispath);
  97. end;
  98. else do
  99.   DKBfile = fullname;
  100. end;
  101.  
  102.   address command cmdpath||'DKBRD c "'||DKBfile||'"';
  103.   if rc ~= 0 then do
  104.     address(prtnme);
  105.     'message "Cannot read '||DKBfile||'"';
  106.     exit 0; /* this is not a proper DKB file */
  107.     end;
  108.  
  109.   call open(fhandle,'ram:IP_LDDKB.tmp','read');      /* open the file */
  110.   rstring = readln(fhandle);
  111.   call close(fhandle);                     /* close the file    */
  112.   
  113.   address command 'c:delete >nil: ram:IP_LDDKB.tmp';
  114.   
  115.   parse var rstring width '/' height
  116.  
  117.   if height < 0 then do
  118.     'message "Bad Height: '||height||'"';
  119.     exit 0;
  120.     end;
  121.  
  122.   if height > 32767 then do
  123.     'message "Bad Height: '||height||'"';
  124.     exit 0;
  125.     end;
  126.  
  127.   if width < 0 then do
  128.     'message "Bad Width: '||width||'"';
  129.     exit 0;
  130.     end;
  131.  
  132.   if width > 32767 then do
  133.     'message "Bad Width: '||width||'"';
  134.     exit 0;
  135.     end;
  136.  
  137.   address(prtnme);
  138.   
  139.   'imtofront'; /* show user the IM screen */
  140.   /* is there already a primary buffer??? */
  141.   options results;
  142.   'current';
  143.   bufdata = result;
  144.   options;
  145.  
  146.   mknewbuff = 1;
  147.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  148.   if bname ~= '<none>' then
  149.     do
  150.       address(prtnme);
  151.       options results;
  152.       if (bx = width) & (by = height) then
  153.         do
  154.           'askyn '||'"Merge Primary ['||bname||']" "New Buffer"'
  155.           prefs = result;
  156.           options;
  157.           address;
  158.           if prefs = 0 then
  159.             do
  160.               address(prtnme);
  161.               'rename '||bnum||' 'gxname;
  162.               mknewbuff = 0;
  163.               address;
  164.             end;
  165.           else
  166.             do
  167.               mknewbuff = 1;
  168.               'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  169.               prefs = result;
  170.               options;
  171.               address;
  172.               if prefs = 0 then
  173.                 do
  174.                   address(prtnme);
  175.                   'killbuff '||bnum; /* this kills the Primary Buffer */
  176.                   address;
  177.                 end;
  178.             end;
  179.         end;
  180.       else
  181.           do
  182.             mknewbuff = 1;
  183.             'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  184.             prefs = result;
  185.             options;
  186.             address;
  187.             if prefs = 0 then
  188.               do
  189.                 address(prtnme);
  190.                 'killbuff '||bnum; /* this kills the Primary Buffer */
  191.                 address;
  192.               end;
  193.           end;
  194.     end;
  195.  
  196.   if mknewbuff = 1 then do
  197.     /* New buffer is created at current resolution */
  198.     address(prtnme);
  199.     'autoredraw 0';
  200.     options results;
  201.     'newbuf '||width||' '||height;
  202.     if rc ~= 0 then do
  203.       "message Can't allocate buffer!";
  204.       'autoredraw 1';
  205.       exit 0;
  206.       end
  207.     bnum = result;
  208.     options;
  209.     'newcurrent '||bnum;
  210.     'rename '||bnum||' 'gxname;
  211.     'autoredraw 1';
  212.     address;
  213.   end;
  214.  
  215.   address(prtnme);
  216.   options results;
  217.   'jackin';
  218.   jackadr = result;
  219.   options;
  220.  
  221.   'wbtofront';
  222.   'lockimage '||bnum;
  223.   address command cmdpath||'DKBRD d'||jackadr||' "'||DKBfile||'"';
  224.   'unlockimage '||bnum;
  225.  
  226.   address(prtnme);
  227.   'imtofront';
  228.   'redraw';
  229.   'finish';
  230.   address;
  231.  
  232.   exit 0;
  233.  
  234. /*
  235.  * gimmepath
  236.  *
  237.  * This takes the provided argument and sucks the path out of it, then
  238.  * returns that path to the caller, sans file name.
  239.  */
  240. gimmepath:
  241.   arg fullnamegx;
  242.     tempgx = reverse(fullnamegx);
  243.     lengx = length(fullnamegx);   /* get length of string */
  244.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  245.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  246.     seploc = 0; /* assumes current dir, no path supplied */
  247.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  248.       seploc = (lengx - slashdex)+1;
  249.       end;
  250.     else do
  251.       if colondex ~= 0 then do /* we assume we are on a device */
  252.         seploc = (lengx - colondex)+1;
  253.         end;
  254.       end;
  255.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  256.   gxpath = left(fullnamegx,seploc);
  257.   return(gxpath);
  258.  
  259. /*
  260.  * Since this script can't be expected to know where the CD of the user
  261.  * is when this cmd is invoked, we have to check the path the user
  262.  * provides - if it's not specified right from a root, then we have
  263.  * to make it a complete specification from the root.
  264.  */
  265. expandfilename:
  266.   parse arg jfile;
  267.   if index(jfile,':') = 0 then do
  268.     curdir = pragma(D);
  269.     if right(curdir,1) ~= ':' then do
  270.       if right(curdir,1) ~= '/' then do
  271.         if curdir ~= '' then do
  272.           curdir = curdir || '/';
  273.           end;
  274.         end;
  275.       end;
  276.     jfile = curdir||jfile;
  277.     end;
  278.   return(jfile);
  279.  
  280. rvalue:
  281.   wordnum = c2d(readch(fhandle,1)) * 256;
  282.   wordnum = wordnum + c2d(readch(fhandle,1));
  283.   return wordnum;
  284.  
  285.